package com.changanw.account.service;

import com.changanw.account.mapper.AccountMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AccountService {
    @Autowired
    AccountMapper accountMapper;

    public boolean deductAccount(String account,Double money){
        //先查询在更新
        Double moneyByAccount = accountMapper.getMoneyByAccount(account);
        if (moneyByAccount < money){
            throw new RuntimeException("余额不足");
        }
        int i = accountMapper.updateAccount(account, money);
        return i==1;
    }
}
